package com.sdy.usercenter.mq.consumer;

import com.sdy.mq.base.BaseMessageConsumer;
import com.sdy.usercenter.biz.constants.MqConstants;
import com.sdy.usercenter.mq.service.UsercenterMsgFacade;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.Charset;

@Slf4j
@Component
public class UserCenterMessageConsumer extends BaseMessageConsumer {
    @Autowired
    private UsercenterMsgFacade usercenterMsgFacade;

    @Override
    protected boolean consume(MessageExt message) {
        String msgBody = null;
        switch (message.getTags()) {
            case MqConstants.Tags.TAG_OP_LOG:
                msgBody = new String(message.getBody(), Charset.forName(RemotingHelper.DEFAULT_CHARSET));
                usercenterMsgFacade.consumeOpLog(msgBody);
                break;
            default:
                break;
        }
        return true;
    }
}
